"""
Copyright (c) 2022 Guangdong University of Technology
PhotLab is licensed under [Open Source License].
You can use this software according to the terms and conditions of the [Open Source License].
You may obtain a copy of [Open Source License] at: [https://open.source.license/]

THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.

See the [Open Source License] for more details.

Author: Meng Xiang, Junjiang Xiang
Created: 2023/8/19
Supported by: National Key Research and Development Program of China
"""


import numpy as np
import scipy as sci


def driver(input, amplify_type= 1, output_power = 1, gain= 3, active = 1):
    """电放大器

    Args:
        input: 数据
        amplify_type:模式选择
        output_power：输出功率
        gain：增益大小
        active：模块开启

    Returns:

    """

    if active == 1:
        if amplify_type == 1:
            input_power = np.mean(np.abs(input) ** 2)
            gain = 10 * np.log(output_power / input_power, 10)
            gain_alpha = np.log(10 ** (gain / 10)) / 2
        elif amplify_type == 0:
            gain_alpha = np.log(10 ** (gain / 10)) / 2
    Hf = np.exp(gain_alpha)
    amplified_output = sci.ifft(sci.fft(input) * Hf)
    return amplified_output
